import { listReviewingChapterUsingGet } from "@/services/novel-web/chapterController";
import { MessageError } from "@/utils/commonUtils";
import { ApiFilled } from "@ant-design/icons";
import { history } from "@umijs/max";
import { Button, Divider, Row, Space, Table } from "antd";
import { ColumnsType } from "antd/es/table";
import { useEffect, useState } from "react";



const ReviewMsgs: React.FC = ()=>{
  const [data,setData] = useState<API.ChapterInfo[]>([]);

  const loadChapters = async ()=> {
    try {
      const resp = await listReviewingChapterUsingGet();
     
      setData(resp.data ?? []);
      
    } catch (error) {
      MessageError(error);
    }
  };

  useEffect(()=>{
    loadChapters();
  },[]);

 
  // table.标题行
  const columns: ColumnsType<API.ChapterInfo> =[
    {
      title: 'id',
      dataIndex: 'id',
      hidden: true,
    },
    {
      title: '作者',
      dataIndex: ['novelVO','user'],
      render: (value: API.UserVO)=>(
        <a href={`/user/${value.id}`}>{`${value.nickname} #${value.id}`}</a>
      ),
    },
    {
      title: '小说名称',
      dataIndex: ['novelVO','name'],
    },
    {
      title: '章节名称',
      dataIndex: 'title',
    },
    {
      title: '操作',
      render: (_,record)=>(
        <Space size={'middle'}>
          <a onClick={()=>handleReviewAction(record)}>
            {"审核"}
          </a>
        </Space>
      ),
    }
  ];

  const handleReviewAction = (record: API.Chapter) => {
    history.push("/admin/review",{
      data: record,
    });
  };


  return (
    <div>
      <Row align={"middle"} justify={"space-between"} style={{ margin: 8 }}>
        <div style={{ fontWeight: "bolder", fontSize: 16 }}>
          {"审核管理"}
        </div>
        {/* <Button type="primary" onClick={()=>handleToNew()}>
          {"btntext"}
        </Button> */}
      </Row>
      <Divider/>
      <Table<API.ChapterInfo>
        dataSource={data}
        columns={columns}
        size={"middle"}
        pagination={false}
      >
        
      </Table>
    </div>
  );
};

export default ReviewMsgs;

